using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace MVExplorer
{
	public partial class ColorPicker : System.Windows.Controls.UserControl
	{
		public event EventHandler Canceled;
		public event EventHandler Picked;

		public ColorPicker()
		{
			InitializeComponent();

			cmdCancel.Click += new RoutedEventHandler(cmdCancel_Click);

			foreach (Button btn in wrapColorPicker.Children)
			{
				string color = System.Configuration.ConfigurationManager.AppSettings[btn.Name];
				if (!string.IsNullOrEmpty(color))
				{
					btn.Background = new SolidColorBrush((Color)ColorConverter.ConvertFromString(color));
				}
			}
		}

		void cmdCancel_Click(object sender, RoutedEventArgs e)
		{
			if (Canceled != null)
				Canceled(this, new EventArgs());
			e.Handled = true;
		}

		void colors_Click(object sender, RoutedEventArgs e)
		{
			Button btn = sender as Button;
			if (btn == null)
			{
				System.Diagnostics.Debug.Assert(false);
				return;
			}

			brush = btn.Background;

			if (Picked != null)
				Picked(this, new EventArgs());
			e.Handled = true;
		}

		private Brush brush = Brushes.Black;

		public Brush PickedBrush
		{
			get { return brush; }
			set { brush = value; }
		}
	}
}